package com.dces.jx.billtest.exgCurrManage.service;
import com.xdo.domain.PageParam;
import com.dces.jx.billtest.dto.exgCurrManage.*;
import com.xdo.common.token.UserInfoToken;
import com.xdo.domain.ResultObject;
import com.xdo.common.base.service.BaseService;
import com.dces.jx.billtest.exgCurrManage.dao.EmsCusExgCurMapper;
import com.dces.jx.billtest.exgCurrManage.mapper.EmsCusExgCurDtoMapper;
import com.dces.jx.billtest.exgCurrManage.model.EmsCusExgCur;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import jdk.nashorn.internal.runtime.options.Option;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.common.Mapper;
import javax.annotation.Resource;
import java.beans.Transient;
import java.util.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
/**
 * generated by Generate 神码
 * Service;
 *
 * @author xdoV2.0
 * @date: 2021-9-15
 */
@Service
public class EmsCusExgCurService extends BaseService<EmsCusExgCur> {
    @Resource
    private EmsCusExgCurMapper emsCusExgCurMapper;
    @Resource
    private EmsCusExgCurDtoMapper emsCusExgCurDtoMapper;
    @Override
    public Mapper<EmsCusExgCur> getMapper() {
        return emsCusExgCurMapper;
    }
    /**
     * 获取分页信息
     *
     * @author zuzhu
     * @param emsCusExgCurParam
     * @param pageParam
     * @return
     */
    public ResultObject<List<EmsCusExgCurDto>> getListPaged(EmsCusExgCurParam emsCusExgCurParam, PageParam pageParam) {
        // 启用分页查询
        EmsCusExgCur emsCusExgCur = emsCusExgCurDtoMapper.toPo(emsCusExgCurParam);
        Page<EmsCusExgCur> page = PageHelper.startPage(pageParam.getPage(), pageParam.getLimit(), pageParam.getSortOrderContent())
                .doSelectPage(() -> emsCusExgCurMapper.getList(emsCusExgCur));
        List<EmsCusExgCurDto> emsCusExgCurDtos = page.getResult().stream().map(head -> {
            EmsCusExgCurDto dto = emsCusExgCurDtoMapper.toDto(head);
            return dto;
        }).collect(Collectors.toList());
		ResultObject<List<EmsCusExgCurDto>> paged = ResultObject.createInstance(emsCusExgCurDtos, (int) page.getTotal(), page.getPageNum());
        return paged;
    }
    /**
     * 功能描述:查询所有数据
     *
     * @param exportParam
     * @param userInfo
     * @return
     */
    public List<EmsCusExgCurDto> selectAll(EmsCusExgCurParam exportParam, UserInfoToken userInfo) {
        EmsCusExgCur emsCusExgCur = emsCusExgCurDtoMapper.toPo(exportParam);
        // emsCusExgCur.setTradeCode(userInfo.getCompany());
        List<EmsCusExgCurDto> emsCusExgCurDtos = new ArrayList<>();
        List<EmsCusExgCur> emsCusExgCurs = emsCusExgCurMapper.getList(emsCusExgCur);
        if (CollectionUtils.isNotEmpty(emsCusExgCurs)) {
            emsCusExgCurDtos = emsCusExgCurs.stream().map(head -> {
                EmsCusExgCurDto dto = emsCusExgCurDtoMapper.toDto(head);
                return dto;
            }).collect(Collectors.toList());
        }
        return emsCusExgCurDtos;
    }
}
